package com.zoran.study.spring.core;

import org.junit.Test;
import org.springframework.util.concurrent.ListenableFutureTask;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * AsynTaskTest
 *
 * @author zouxm
 * @date 2018/4/3
 */
public class AsynTaskTest1 {

    final ExecutorService executorService = Executors.newSingleThreadExecutor();
    @Test
    public void testListenableFutureTask1() throws InterruptedException {
        ListenableFutureTask<String> task=new ListenableFutureTask<>(() -> {
            Thread.sleep(5000L);
            return "success";
        });

        task.addCallback(result -> System.out.println(result),Throwable::printStackTrace);
        executorService.submit(task);
        System.out.println("main continue...");
        Thread.sleep(10000L);
    }
}
